package com.pls.action;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;


import com.pls.actionObjects.GetSeatMapByQuadrantRequest;
import com.pls.actionObjects.GetSeatMapByQuadrantResponse;
import com.pls.constants.ValidationErrorEnum;
import com.pls.dao.DAOFactory;
import com.pls.dao.SeatDAO;
import com.pls.domain.EmployeeWorkstation;
import com.pls.domain.ExceptionError;
import com.pls.domain.ValidationError;

public class GetSeatMapByQuadrantHandler extends BaseRequestHandler <GetSeatMapByQuadrantResponse, GetSeatMapByQuadrantRequest>{

	Logger logger = Logger.getLogger(GetSeatMapByFloorHandler.class);
	
	public GetSeatMapByQuadrantHandler(Class<GetSeatMapByQuadrantResponse> tResponse) {
		super(tResponse);
	}
	protected ArrayList<ValidationError> validate(
			GetSeatMapByQuadrantRequest request) {
		ArrayList<ValidationError> errors = new ArrayList<ValidationError>();
		ValidationError valError;
		if (request == null) {
			valError = new ValidationError();
			valError.setMessage("Request is null.");
			valError.setErrorName(ValidationErrorEnum.NullRequest);
			errors.add(valError);
			return errors;
		}
		
		return errors;
	}

	public GetSeatMapByQuadrantResponse process(GetSeatMapByQuadrantRequest request) {

		GetSeatMapByQuadrantResponse response = new GetSeatMapByQuadrantResponse();
		List<EmployeeWorkstation> employeeWorkstation;
		
		// call data layer
		SeatDAO seatDAO = DAOFactory.getSeatDAO();

	

		try {	
			logger.debug("Process for GetSeatMapByQuadrantResponse entered.");

			employeeWorkstation = seatDAO.getSeatPlanByQuadrant(
					request.getLocation(), request.getQuadrant());
			response.setLocationSeatMap(employeeWorkstation);
			
			return response;

		
		
		} catch (SQLException e) {
			//ADD LOGGER
			ExceptionError sqlError = new ExceptionError(e.getClass().toString(),
					"Sorry, an SQL error occurred while accessing the DB.");
			response.setExceptionError(sqlError);
		} catch (Exception e) {
			ExceptionError sqlError = new ExceptionError(e.getClass().toString(),
					"Sorry, an error occurred while accessing the DB.");
			response.setExceptionError(sqlError);
		}
		return response;
	}
}